package com.gwtprocessingjs.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

/**  Main entry point module for Gwt Processing communication demos. */
public class GwtProcessingJs implements EntryPoint {

	// UI Elements.
	private final FlowPanel back = new FlowPanel();
	private final Grid grid = new Grid(11, 2);			
	private int rowCount = 0;
	
	@Override
	public void onModuleLoad() {
		back.add(grid);
		addRow("ProcessingPde", "Rendering Processing pde script.");
		addRow("ProcessingJs", "Rendering Processing.js script.");
		addRow("GwtToPde", "Pushing data from GWT to pde script.");
		addRow("GwtToJs", "Pushing data from GWT to Processing.js javascript.");
		addRow("GwtFromPde", "Pulling data from pde to GWT.");
		addRow("GwtFromJs", "Pulling data from processing.js javascript to GWT.");
		addRow("JsToGwt", "Pushing data from processing.js javascript to GWT.");
		addRow("JsFromGwt", "Pulling data from GWT to processing.js javascript.");
		addRow("AddPdeCanvas", "Dynamic canvas addition and removal.");
		addRow("PdeColorPicker", "Color picker widget written in processing script.");
		addRow("JsColorPicker", "Color picker widget written in processing.js javascript.");		
		RootPanel.get("gwt").add(back);
	}

	// --- Private Methods ---
	
	private void addRow(String demoName, String description) {
		HTML link = new HTML(
				"<a href=\"resources/" + demoName + "/" + demoName +
				".html\">" + demoName + "</a>");
		Label label = new Label(description);
		link.setWidth("110px");
		grid.setWidget(rowCount, 1, link);
		grid.setWidget(rowCount, 0, label);
		rowCount++;	
	}
}
